package thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author hubert
 * @date 2018/10/10
 * @description ThreadTest2
 */
public class ThreadTest2 {

	public static void main(String[] args) {
		//创建一个可重用固定线程数的线程池
		ExecutorService pool = Executors.newFixedThreadPool(2);

		//创建实现了Runnable接口对象，Thread对象当然也实现了Runnable接口
		Thread t1 = new MyThread("t1",1);

		Thread t2 = new MyThread("t2",2);

		Thread t3 = new MyThread("t3",3);

		Thread t4 = new MyThread("t4",4);

		Thread t5 = new MyThread("t5",5);

		//将线程放入池中进行执行

		pool.execute(t1);

		pool.execute(t2);

		pool.execute(t3);

		pool.execute(t4);

		pool.execute(t5);

		try {
			Thread.sleep(3000L);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println("中断线程1");
		t1.interrupt();

		//关闭线程池

		pool.shutdown();
	}
}
